package com.qlzb.taskmanagement.task;

import com.qlzb.taskmanagement.configure.QuartzManager;
import com.qlzb.taskmanagement.entity.CronInfoEntity;
import com.qlzb.taskmanagement.util.HttpUtils;
import com.qlzb.taskmanagement.vo.quartzVo.QuartzUserList;
import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.quartz.SchedulerException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class CreateCrawlerTask implements Job {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
//    @Autowired
//    private MainCrawlerTask mainCrawlerTask;
    @Autowired
    QuartzManager quartzManager;
    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        logger.info("crawlerTask task start execute.");
        String qname=jobExecutionContext.getJobDetail().getKey().getName();
        String url=jobExecutionContext.getJobDetail().getJobDataMap().getString("url");
        String message = HttpUtils.sendPost(url);
    }

    public void startMainCrawlerTask(){
        for (CronInfoEntity cronEntitys : QuartzUserList.cronEntitys) {
            try {
                logger.info("开始创建定时任务-"+cronEntitys.getQuarzName()+"--表达式-"+cronEntitys.getCron());
                quartzManager.start(cronEntitys.getUrl());
            } catch (SchedulerException e) {
                e.printStackTrace();
            }
        }

    }
}
